/**
 * 
 */
package model.entity;

/**
 * @author Ozzy
 *
 */
public class Wander extends AIBehavior {

	/**
	 * Wander specifies the wandering behavior. This is specified by two values, the wanderRate
	 * that determines how often an entity moves, and the wanderRange, which specifies how far 
	 * they will wander from their original spot.
	 */
	
	private Integer wanderRate;
	private Integer wanderRange;
	private int count,x,y;
	
	public Wander(Integer rate, Integer range) {
		this.wanderRate=rate;
		this.wanderRange=range;
		count = 0;

	}
	
	public Wander(){
		this.wanderRate=new Integer(150);
		this.wanderRange=new Integer(5);
	}
	
	public void update(Entity e){
		count++;
		if (count > wanderRate){
			
			if (Math.random()>.5){
			
				int moveDeterminer = (int) Math.rint(Math.random()*5);
			
				switch (moveDeterminer){
				case 0: x++; y++; if (Math.sqrt(((x*x)+(y*y)))<wanderRange){e.commandMoveNE();} else{x--; y--;} break;
				case 1: y++; if (Math.sqrt(((x*x)+(y*y)))<wanderRange){e.commandMoveNorth();} else{y--;} break;
				case 2: y++; x--; if (Math.sqrt(((x*x)+(y*y)))<wanderRange){e.commandMoveNW();} else{y--; x++;} break;
				case 3: y--; x++; if (Math.sqrt(((x*x)+(y*y)))<wanderRange){e.commandMoveSE();} else{y++; x--;} break;
				case 4: y--; if (Math.sqrt(((x*x)+(y*y)))<wanderRange){e.commandMoveSouth();} else{y++;} break;
				case 5: y--; x--; if (Math.sqrt(((x*x)+(y*y)))<wanderRange){e.commandMoveSW();} else{x++; y++;} break;
				}
			}
			count = 0;

		}
	}

}
